worker_processes auto;
events {
    worker_connections 1024;
}
http {
    resolver 127.0.0.11;
    server_tokens off;
    charset utf-8;

    server {
        listen 80 default_server;

        server_name _;

        location / {
            proxy_pass http://$host:3000;
        }

        location /api/ {
            proxy_pass http://$host:8000$request_uri;
            proxy_set_header    Host $host;
            proxy_set_header    X-Forwarded-Proto $scheme;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect      off;
        }

        location /swagger/ {
            proxy_pass http://$host:8000;
            proxy_set_header    Host $host;
            proxy_set_header    X-Forwarded-Proto $scheme;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect      off;
        }

        location /static/ {
            proxy_pass http://$host:8000;
            proxy_set_header    Host $host;
            proxy_set_header    X-Forwarded-Proto $scheme;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect      off;
        }
    }

    server {
        server_name $host;

        location / {
            proxy_pass http://$host:3000;
        }

        location /api/ {
            proxy_pass http://$host:8000$request_uri;
            proxy_set_header    Host $host;
            proxy_set_header    X-Forwarded-Proto $scheme;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect      off;
        }

        location /swagger/ {
            proxy_pass http://$host:8000;
            proxy_set_header    Host $host;
            proxy_set_header    X-Forwarded-Proto $scheme;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect      off;
        }

        location /static/ {
            proxy_pass http://$host:8000;
            proxy_set_header    Host $host;
            proxy_set_header    X-Forwarded-Proto $scheme;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect      off;
        }

        listen 443 ssl;
        ssl_certificate /etc/letsencrypt/live/akhmetovi-dev.ru/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/akhmetovi-dev.ru/privkey.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    }

    server {
        if ($host = akhmetovi-dev.ru) {
            return 301 https://$host$request_uri;
        }


        server_name SERVER_NAME;
        listen 80;
        return 404;
    }
}